import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { reqIdlePayload } from "../utils/apiHandler";
import { RequestResponseType } from "./index.types";

const initialState = {
  login: reqIdlePayload as RequestResponseType,
  isUserLoggedIn: false,
};

const authSlice = createSlice({
  name: "authApi",
  initialState,
  reducers: {
    loginUserReq(state, action: PayloadAction<RequestResponseType>) {
      state.login = action.payload;
    },
    userLoginAction(state, action) {
      state.isUserLoggedIn = action.payload;
    },
  },
});

export const { loginUserReq, userLoginAction } = authSlice.actions;
export default authSlice.reducer;
